package com.test.deencredit.analytics_deencredit.data_sdk_deencredit.task_deencredit;

import android.content.Context;
import android.text.TextUtils;

import com.test.deencredit.analytics_deencredit.data_sdk_deencredit.beans_deencredit.ASRequestPms_deencredit;
import com.test.deencredit.analytics_deencredit.data_sdk_deencredit.http_deencredit.ASReqstManger_deencredit;
import com.test.deencredit.analytics_deencredit.data_sdk_deencredit.logger_deencredit.ASLger_deencredit;
import com.test.deencredit.analytics_deencredit.data_sdk_deencredit.services_deencredit.ASStoeIfo_deencredit;
import com.test.deencredit.config_deencredit.CountryConfig_deencredit;
import com.test.deencredit.config_deencredit.Paths_deencredit;

import java.util.function.Supplier;


public class ASDevcStorTsk_deencredit implements Supplier<String> {

    private final static String TAG = "ASDeviceStoreTask";

    private final String mTaskId;
    private final Context mContext;

    public ASDevcStorTsk_deencredit(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get()  {
        // 日志标记
        ASLger_deencredit.d_deencredit(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(Paths_deencredit.PATH_STORAGE_deencredit)) {
            return mTaskId + "";
        }

        String infoBeans = ASStoeIfo_deencredit.getZipString_deencredit(mContext);
        if (TextUtils.isEmpty(infoBeans)) {
            // 日志标记
            ASLger_deencredit.d_deencredit(TAG, "获取存储信息出错：数据为空");
            return mTaskId + "";
        }

        ASRequestPms_deencredit netParams = new ASRequestPms_deencredit();
        netParams.setDSG_deencredit(infoBeans);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams_deencredit(Paths_deencredit.PATH_STORAGE_deencredit);

        // 上报请求
        String url = CountryConfig_deencredit.getInstance_deencredit().getCommonPath_deencredit();
        new ASReqstManger_deencredit.Builder_deencredit().setReqId_deencredit(this.mTaskId).setUrl_deencredit(url).setBody_deencredit(result).build_deencredit().doPostRqst_deencredit();

        return mTaskId + "";
    }
}
